﻿using JNPF.Basics.Logic;
using JNPF.Basics.Models;
using JNPF.Basics.Models.WorkFlowForm.Dtos.TravelReimbursement;
using JNPF.Utils;
using JNPF.Utils.Controller;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace JNPF.Basics.Controller
{
    /// <summary>
    /// 差旅报销申请表
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2018-01-23
    /// </summary>
    [Route("api/WorkFlowForm/TravelReimbursement")]
    public class TravelReimbursementController : BaseApiController
    {
        private TravelReimbursementBll travelReimbursementBll = new TravelReimbursementBll();

        #region GET
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<ResponseResult> GetInfo(string id)
        {
            var data = (await travelReimbursementBll.GetInfo(id)).MapTo<TravelReimbursementInfoOutput>();
            return Success(data);
        }
        #endregion

        #region POST
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="input">表单信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseResult> Save([FromBody] TravelReimbursementCrInput input)
        {
            var entity = input.MapTo<TravelReimbursementEntity>();
            if (input.status == 1)
            {
                await travelReimbursementBll.Save(entity.Id, entity);
                return Success("保存成功");
            }
            await travelReimbursementBll.Submit(entity.Id, entity);
            return Success("提交成功，请耐心等待");
        }
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="id">主键</param>
        /// <param name="input">表单信息</param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<ResponseResult> Submit(string id, [FromBody] TravelReimbursementUpInput input)
        {
            input.id = id;
            var entity = input.MapTo<TravelReimbursementEntity>();
            if (input.status == 1)
            {
                await travelReimbursementBll.Save(entity.Id, entity);
                return Success("保存成功");
            }
            await travelReimbursementBll.Submit(entity.Id, entity);
            return Success("提交成功，请耐心等待");
        }
        #endregion
    }
}
